using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CCShootAction : SSAction
{
    private Vector3 pulseForce;  //射箭冲量
    private CCShootAction() { }
    // Start is called before the first frame update
    public override void Start()
    {
        gameobject.transform.parent = null;
        gameobject.GetComponent<Rigidbody>().useGravity = true; // 发射后开启重力
        gameobject.GetComponent<Rigidbody>().velocity = Vector3.zero; // 初速度0
        gameobject.GetComponent<Rigidbody>().AddForce(pulseForce, ForceMode.Impulse); // 给箭添加冲量
        gameobject.GetComponent<Rigidbody>().isKinematic = false; // 关闭运动学控制
    }

    // Update is called once per frame
    public override void Update()
    {
        
    }

    // 获得射箭动作实例
    public static CCShootAction GetSSAction(Vector3 impulseDirection, float power) {
        CCShootAction shootArrow = CreateInstance<CCShootAction>();
        shootArrow.pulseForce = impulseDirection.normalized * power;
        return shootArrow;
    }

    public override void FixedUpdate()
    { // 是否飞出场景或落在地上或射中靶子
        if (!gameobject || this.gameobject.tag == "ground" || this.gameobject.tag == "onTarget") {
            this.destroy = true;
            this.callback.SSActionEvent(this);
        }
    }
}
